#include "vector2d.h"

Vector2d::Vector2d()
{
    x(0);
    y(0);
}

Vector2d::Vector2d(float a,float b){
    x(a);
    y(b);
}

float Vector2d::x() const{
    return vec[0];
}

void  Vector2d::x(float a){
    vec[0] = a;
}

float Vector2d::y() const{
    return vec[1];
}

void  Vector2d::y(float b){
    vec[1] = b;
}

const Vector2d& Vector2d::operator +(const Vector2d& b) const{
    Vector2d a = *this;
    a.x(a.x() + b.x());
    a.y(a.y() + b.y());
    return a;
}

const Vector2d& Vector2d::operator *(float value) const{
    Vector2d a = *this;
    a.x(value * a.x());
    a.y(value * a.y());
    return a;
}

const Vector2d& Vector2d::operator /(float value) const{
    Vector2d a = *this;
    return a * (1/value);
}

const Vector2d& Vector2d::operator -(const Vector2d& b) const{
    Vector2d a = *this;
    return a + b*(-1);
}


Vector2d& Vector2d::operator += (const Vector2d& mas){
    x(x() + mas.x());
    y(y() + mas.y());
    return *this;
}

float Vector2d::abs() const{
    return sqrt(x()*x() + y()*y());
}

const Vector2d&  Vector2d::normal() const{
    Vector2d a = *this;
    return a*(1/a.abs());
}
